#include "stdafx.h"
#include "GraphicsResources.h"

#include "MeshManager.h"
#include "ModelManager.h"
#include "TextureManager.h"
#include "ShaderManager.h"
#include "InputLayoutManager.h"
#include "MaterialManager.h"
#include "StateManager.h"

#include "Effects.h"

using namespace mgfx;

GraphicsResources * GraphicsResources::getGlobal()
{
	static GraphicsResources gr;
	return &gr;
}

GraphicsResources::GraphicsResources()
{
	ZeroMemory(this, sizeof(GraphicsResources));
}

void GraphicsResources::init(ID3D10Device* device)
{
	fx::InitAll(device);
	
	mInputLayoutMgr = new InputLayoutManager;
	mInputLayoutMgr->init(device);

	mStateMgr = new StateManager;
	mStateMgr->init(device);

	mShaderMgr = new ShaderManager;
	mShaderMgr->init(device);

	mMeshMgr = new MeshManager;
	mMeshMgr->init();

	mTextureMgr = new TextureManager;
	mTextureMgr->init(device);

	mMaterialMgr = new MaterialManager;
	mMaterialMgr->init();

	mModelMgr = new ModelManager;
	mModelMgr->init();
}

void GraphicsResources::deinit()
{
	mModelMgr->deinit();
	delete mModelMgr;

	mMaterialMgr->deinit();
	delete mMaterialMgr;

	mTextureMgr->deinit();
	delete mTextureMgr;

	mMeshMgr->deinit();
	delete mMeshMgr;

	mShaderMgr->deinit();
	delete mShaderMgr;

	mStateMgr->deinit();
	delete mStateMgr;

	mInputLayoutMgr->deinit();
	delete mInputLayoutMgr;

	fx::DestroyAll();
}

MeshManager * GraphicsResources::getMeshMgr()
{
	assert(mMeshMgr != NULL);
	return mMeshMgr;
}

ModelManager * GraphicsResources::getModelMgr()
{
	assert(mModelMgr != NULL);
	return mModelMgr;
}

TextureManager * GraphicsResources::getTextureMgr()
{
	assert(mTextureMgr != NULL);
	return mTextureMgr;
}

ShaderManager * GraphicsResources::getShaderMgr()
{
	assert(mShaderMgr != NULL);
	return mShaderMgr;
}

InputLayoutManager * GraphicsResources::getInputLayoutMgr()
{
	assert(mInputLayoutMgr != NULL);
	return mInputLayoutMgr;
}

MaterialManager * GraphicsResources::getMaterialMgr()
{
	assert(mMaterialMgr != NULL);
	return mMaterialMgr;
}

StateManager * GraphicsResources::getStateMgr()
{
	assert(mStateMgr != NULL);
	return mStateMgr;
}